﻿Public Class SettingsForm
    Private _mainForm As Form

#Region "Constructors"

    Public Sub New(ByVal mainForm As Form)
        Me.InitializeComponent()
        _mainForm = mainForm
    End Sub

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)
        For Each printer As String In Printing.PrinterSettings.InstalledPrinters
            ListBoxTicketPrinter.Items.Add(printer)
            ListBoxGewonePrinter.Items.Add(printer)
        Next printer

        If (ListBoxTicketPrinter.Items.Contains(Configuratie.TicketPrinter)) Then
            ListBoxTicketPrinter.SelectedIndex = ListBoxTicketPrinter.FindString(Configuratie.TicketPrinter)
        End If

        If (ListBoxGewonePrinter.Items.Contains(Configuratie.Printer)) Then
            ListBoxGewonePrinter.SelectedIndex = ListBoxGewonePrinter.FindString(Configuratie.Printer)
        End If

        CheckBoxTicketsAfdrukken.Checked = Configuratie.TicketAfdrukken
        CheckBoxKasbladAfdrukken.Checked = Configuratie.KasBladAfdrukken
        CheckBoxLeveringsbonAfdrukken.Checked = Configuratie.LeveringsbonAfdrukken

        TextBoxTekstOpTicket.Text = Configuratie.TekstOpTicket
    End Sub

#End Region

#Region "Events"

    Protected Overrides Sub OnKeyUp(ByVal e As System.Windows.Forms.KeyEventArgs)
        MyBase.OnKeyUp(e)
        Select Case e.KeyCode
            Case Keys.F2
                btnOK_Click(Me, EventArgs.Empty)
        End Select
    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If (ListBoxTicketPrinter.SelectedIndex >= 0) Then
            Configuratie.TicketPrinter = Printing.PrinterSettings.InstalledPrinters.Item(ListBoxTicketPrinter.SelectedIndex)
        End If
        If (ListBoxGewonePrinter.SelectedIndex >= 0) Then
            Configuratie.Printer = Printing.PrinterSettings.InstalledPrinters.Item(ListBoxGewonePrinter.SelectedIndex)
        End If

        Configuratie.TicketAfdrukken = CheckBoxTicketsAfdrukken.Checked
        Configuratie.KasBladAfdrukken = CheckBoxKasbladAfdrukken.Checked
        Configuratie.LeveringsbonAfdrukken = CheckBoxLeveringsbonAfdrukken.Checked

        Configuratie.TekstOpTicket = TextBoxTekstOpTicket.Text

        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

#End Region


End Class